/**
 * 撤销列表
 * @param len 列表的长度
 */
function UndoList(len) {
	ul = this;
	ul.udLen = len
	ul.udCurLen = 0; // 定义列表当前的长度 
	ul.udList = new Array(ul.length); // 使用数组放置列表的数据
	ul.redoList = new RedoList(len, ul);
};

UndoList.prototype = {
	deleteFirstData : function() { // 删除列表的表头元素
		this.udList[0] = null;
	},
	
	moveListData : function() { // 移动列表的数据
		for (var i = 0; i < this.udCurLen; i++) {
			this.udList[i] = this.udList[i + 1];
		}
		this.udList[udCurLen -1] = null;
		udCurLen--;
	},
	
	push : function(data) {
		if (this.udCurLen < this.udLen) {
			this.udList[udCurLen] = data;
			this.udCurLen++;
		} else {
			deleteFirstData();
			moveListData();
			this.udList[udCurLen] = data;
		}
	},
	
	pop : function() {
		this.redoList.push(this.udList[this.udCurLen - 1]);
	}
};

/**
 * 重做列表
 * @param len 列表的长度
 */
function RedoList(len, undo) {
	rl = this;
	rl.rdLen = len
	rl.rdCurLen = 0; // 定义列表当前的长度 
	rl.rdList = new Array(rl.rdLen); // 使用数组放置列表的数据
	rl.UndoList = undo;
};

RedoList.prototype = {
	deleteFirstData : function() { // 删除列表的表头元素
		this.rdList[0] = null;
	},
	
	moveListData : function() { // 移动列表的数据
		for (var i = 0; i < this.rdCurLen; i++) {
			this.rdList[i] = this.rdList[i + 1];
		}
		this.rdList[rdCurLen -1] = null;
		rdCurLen--;
	},
	
	push : function(data) {
		if (this.rdCurLen < this.udLen) {
			this.rdList[rdCurLen] = data;
			this.rdCurLen++;
		} else {
			deleteFirstData();
			moveListData();
			this.rdList[rdCurLen] = data;
		}
	},
	
	pop : function() {
		this.undoList.push(this.rdList[this.rdCurLen - 1]);
	}
}